from google.appengine.ext import webapp
from DataClass.FileData import FileData
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from AdminBase import AdminBase

import os
import cgi

class DeleteFileHandler(AdminBase):
    def GetTemplateFileName(self):
        return 'Pages/deletefile.html'
        
    def GetBreadcrumbList(self):
        return [['main', 'admin'],['files', 'editfiles'],['delete file']]
    
    def GetTemplateValuesDict(self, template_values, user):
        retval = template_values

        Website = template_values['currentwebsite']

        querystring=cgi.FieldStorage()
        filename=querystring.getvalue('filename')
        file=None
    
        if not filename:
            filename = ''
            
        file = FileData.GetFileBySiteNameAndFileName(Website.sitename, filename)

        if file:
            retval['file'] = file
    
        return retval

    def DoPost(self, user):
#        Website = WebsiteRec.GetWebsiteBySiteName(self.request.get('sitename'))
        file = FileData.GetFileBySiteNameAndFileName(self.request.get('sitename'), self.request.get('filename'))

        if file:
            db.delete(file)

        self.redirect('/editfiles')
